<!--
 * @Author: panghu chenjh@datamargin.com
 * @Date: 2024-04-03 09:40:13
 * @LastEditors: panghu chenjh@datamargin.com
 * @LastEditTime: 2024-05-03 23:27:06
 * @FilePath: \zheye\src\components\ColumnList.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="row">
    <div v-for="column in columnList" :key="column._id" class="col-4 mb-4">
      <div class="card h-100 shadow-sm">
        <div class="card-body text-center">
        <img :src="column.avatar?.url" :alt="column.title" class="rounded-circle border border-light my-3">
        <h5 class="card-title">{{ column.title }}</h5>
        <p class="card-text text-left">{{ column.description }}</p>
        <router-link :to="`/column/${column._id}`" class="btn btn-outline-primary">进入专题</router-link>
      </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
import { ColumnProps } from '@/store'
import { addColumnAvatar } from '@/utils/helper'

export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props) {
    // const router = useRouter()
    const columnList = computed(() => {
      return props.list.map(column => {
        addColumnAvatar(column, 50, 50)
        return column
      })
    })
    return {
      columnList
    }
  }
})
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
  margin: 0 10px;
}

a {
  color: #42b983;
}

.card-body img{
  width: 50px;
  height: 50px;
}
</style>
